<?php
// 开启会话
session_start();

// 初始化游戏数据
if (!isset($_SESSION['center'])) {
    $_SESSION['center'] = [
        'money' => 10000, // 初始资金
        'counselors' => 0, // 咨询师数量
        'visitors' => 0, // 来访者数量
        'revenue_per_visitor' => 500, // 每位来访者的收入
        'hire_cost' => 2000, // 招聘一位咨询师的成本
        'capacity_per_counselor' => 5 // 每位咨询师的接待能力
    ];
}

// 处理招聘咨询师操作
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['hire_counselor'])) {
    if ($_SESSION['center']['money'] >= $_SESSION['center']['hire_cost']) {
        $_SESSION['center']['money'] -= $_SESSION['center']['hire_cost'];
        $_SESSION['center']['counselors']++;
        $message = "成功招聘一名咨询师，花费 {$_SESSION['center']['hire_cost']} 元。";
    } else {
        $message = "资金不足，无法招聘咨询师。";
    }
}

// 处理接待来访者操作
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['receive_visitors'])) {
    $capacity = $_SESSION['center']['counselors'] * $_SESSION['center']['capacity_per_counselor'];
    if ($_SESSION['center']['visitors'] <= $capacity) {
        $income = $_SESSION['center']['visitors'] * $_SESSION['center']['revenue_per_visitor'];
        $_SESSION['center']['money'] += $income;
        $message = "成功接待 {$_SESSION['center']['visitors']} 位来访者，收入 $income 元。";
        $_SESSION['center']['visitors'] = 0; // 接待后清空来访者数量
    } else {
        $message = "咨询师接待能力不足，无法接待所有来访者。请招聘更多咨询师。";
    }
}

// 模拟新来访者到来
$_SESSION['center']['visitors'] += rand(1, 10);
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>模拟经营心理咨询中心</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            padding: 20px;
        }

        h1 {
            text-align: center;
            color: #333;
        }

        p {
            margin-bottom: 10px;
        }

        form {
            background-color: #fff;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
            margin-bottom: 20px;
        }

        button {
            padding: 10px 20px;
            background-color: #007BFF;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        .message {
            padding: 10px;
            margin-bottom: 10px;
            border-radius: 5px;
        }

        .success {
            background-color: #d4edda;
            color: #155724;
        }

        .error {
            background-color: #f8d7da;
            color: #721c24;
        }
    </style>
</head>

<body>
    <h1>模拟经营心理咨询中心</h1>
    <p>当前资金: <?php echo $_SESSION['center']['money']; ?> 元</p>
    <p>咨询师数量: <?php echo $_SESSION['center']['counselors']; ?> 名</p>
    <p>当前来访者数量: <?php echo $_SESSION['center']['visitors']; ?> 位</p>

    <?php if (isset($message)): ?>
        <div class="message <?php echo strpos($message, '成功')!== false? 'success' : 'error'; ?>">
            <?php echo $message; ?>
        </div>
    <?php endif; ?>

    <form method="post">
        <button type="submit" name="hire_counselor">招聘咨询师（<?php echo $_SESSION['center']['hire_cost']; ?> 元/人）</button>
    </form>

    <form method="post">
        <button type="submit" name="receive_visitors">接待来访者</button>
    </form>
</body>

</html>